1 using System;
2 using
System.Collections.Generic;
3 using
UnityEditor;
4
5 namespace
UnityStandardAssets.CrossPlatformInput.Inspector
6 {
7     
[InitializeOnLoad]
8     
public class CrossPlatformInitialize
9     {
10         
// Custom compiler defines:
11         
//
12         
// CROSS_PLATFORM_INPUT : denotes that cross platform input package exists, so that other packages can use their CrossPlatformInput functions.
13         
// EDITOR_MOBILE_INPUT : denotes that mobile input should be used in editor, if a mobile build target is selected. (i.e. using Unity Remote app).
14         
// MOBILE_INPUT : denotes that mobile input should be used right now!
15
16         
static CrossPlatformInitialize()
17         {
18             
var defines = GetDefinesList(buildTargetGroups[0]);
19             
if (!defines.Contains("CROSS_PLATFORM_INPUT"))
20             {
21                 SetEnabled(
"CROSS_PLATFORM_INPUT", true, false);
22                 SetEnabled(
"MOBILE_INPUT", true, true);
23             }
24         }
25
26
27         
[MenuItem("Mobile Input/Enable")]
28         
private static void Enable()
29         {
30             SetEnabled(
"MOBILE_INPUT", true, true);
31             
switch (EditorUserBuildSettings.activeBuildTarget)
32             {
33                 
case BuildTarget.Android:
34                 
case BuildTarget.iOS:
35                 
case BuildTarget.PSM:
36                 
case BuildTarget.Tizen:
37                 
case BuildTarget.WSAPlayer:
38                     EditorUtility.DisplayDialog(
"Mobile Input",
39                                                 
"You have enabled Mobile Input. You'll need to use the Unity Remote app on a connected device to control your game in the Editor.",
40                                                 
"OK");
41                     
break;
42
43                 
default:
44                     EditorUtility.DisplayDialog(
"Mobile Input",
45                                                 
"You have enabled Mobile Input, but you have a non-mobile build target selected in your build settings. The mobile control rigs won't be active or visible on-screen until you switch the build target to a mobile platform.",
46                                                 
"OK");
47                     
break;
48             }
49         }
50
51
52         
[MenuItem("Mobile Input/Enable", true)]
53         
private static bool EnableValidate()
54         {
55             
var defines = GetDefinesList(mobileBuildTargetGroups[0]);
56             
return !defines.Contains("MOBILE_INPUT");
57         }
58
59
60         
[MenuItem("Mobile Input/Disable")]
61         
private static void Disable()
62         {
63             SetEnabled(
"MOBILE_INPUT", false, true);
64             
switch (EditorUserBuildSettings.activeBuildTarget)
65             {
66                 
case BuildTarget.Android:
67                 
case BuildTarget.iOS:
68                     EditorUtility.DisplayDialog(
"Mobile Input",
69                                                 
"You have disabled Mobile Input. Mobile control rigs won't be visible, and the Cross Platform Input functions will always return standalone controls.",
70                                                 
"OK");
71                     
break;
72             }
73         }
74
75
76         
[MenuItem("Mobile Input/Disable", true)]
77         
private static bool DisableValidate()
78         {
79             
var defines = GetDefinesList(mobileBuildTargetGroups[0]);
80             
return defines.Contains("MOBILE_INPUT");
81         }
82
83
84         
private static BuildTargetGroup[] buildTargetGroups = new BuildTargetGroup[]
85             {
86                 BuildTargetGroup.Standalone,
87                 BuildTargetGroup.Android,
88                 BuildTargetGroup.iOS
89             };
90
91         
private static BuildTargetGroup[] mobileBuildTargetGroups = new BuildTargetGroup[]
92             {
93                 BuildTargetGroup.Android,
94                 BuildTargetGroup.iOS,
95                 BuildTargetGroup.PSM,
96                 BuildTargetGroup.SamsungTV,
97                 BuildTargetGroup.Tizen,
98                 BuildTargetGroup.WSA
99             };
100
101
102         
private static void SetEnabled(string defineName, bool enable, bool mobile)
103         {
104             
//Debug.Log("setting "+defineName+" to "+enable);
105             
foreach (var group in mobile ? mobileBuildTargetGroups : buildTargetGroups)
106             {
107                 
var defines = GetDefinesList(group);
108                 
if (enable)
109                 {
110                     
if (defines.Contains(defineName))
111                     {
112                         
return;
113                     }
114                     defines.Add(defineName);
115                 }
116                 
else
117                 {
118                     
if (!defines.Contains(defineName))
119                     {
120                         
return;
121                     }
122                     
while (defines.Contains(defineName))
123                     {
124                         defines.Remove(defineName);
125                     }
126                 }
127                 
string definesString = string.Join(";", defines.ToArray());
128                 PlayerSettings.SetScriptingDefineSymbolsForGroup(
group, definesString);
129             }
130         }
131
132
133         
private static List<string> GetDefinesList(BuildTargetGroup group)
134         {
135             
return new List<string>(PlayerSettings.GetScriptingDefineSymbolsForGroup(group).Split(';'));
136         }
137     }
138 }


Gõ tìm kiếm nhanh...